﻿@model cloudscribe.Core.Web.ViewModels.Account.EditUserViewModel
@inject ICoreThemeHelper themeHelper
@inject IStringLocalizer<CloudscribeCore> sr
@inject ICkeditorOptionsResolver editorOptionsResolver
@{
    var ckOptions = await editorOptionsResolver.GetCkeditorOptions();
    var themeSettings = themeHelper.GetThemeSettings();
    if (themeSettings.AdminSideNavExpanded) { ViewData["SideNavToggle"] = "show"; }
    ViewData["SideNavVisible"] = true;

}
@section Styles {
    <partial name="UserEditStylePartial" />
}
<h2>@ViewData["Title"]</h2>
@if (Model.UserId != Guid.Empty && !Model.AccountApproved)
{
    <form class="form-inline" role="form" asp-controller="UserAdmin" asp-action="ApproveUserAccount" asp-route-returnurl='@ViewData["ReturnUrl"]'>
        <input asp-for="UserId" type="hidden" />
        <input asp-for="SiteId" type="hidden" />
        <div class="form-check">
            <input type="checkbox" asp-for="SendApprovalEmail" class="form-check-input" />
            <label asp-for="SendApprovalEmail" class="form-check-label">@sr["Send Email Notification"]</label>
        </div>
        <button type="submit" class="btn btn-success">@sr["Approve this account"]</button>
    </form>
}
<form data-submit-once="true" class="form-horizontal" role="form" asp-controller="UserAdmin" asp-action="UserEdit">
    <input asp-for="UserId" type="hidden" />
    <input asp-for="SiteId" type="hidden" />
    <div class="row">
        <div class="col-md-2">
            <a asp-controller="UserAdmin" asp-action="UserActivity" asp-route-siteid="@Model.SiteId" asp-route-userid="@Model.UserId" title="Activty">
                <img class="pull-right" gravatar-email="@Model.Email" gravatar-size="60" gravatar-enabled="@themeSettings.AllowGravatar" override-url="@Model.AvatarUrl" disabled-default-url="@themeSettings.DefaultAvatarUrl" />
            </a>
        </div>
        <div class="col-md-10 ">
            <div class="form-group">
                <div class="form-check">
                    <input asp-for="EmailConfirmed" class="form-check-input" />
                    <label asp-for="EmailConfirmed" class="form-check-label">@sr["Email Confirmed"]</label>
                </div>
            </div>
            <div class="form-group">
                <div class="form-check">
                    <input asp-for="IsLockedOut" class="form-check-input" />
                    <label asp-for="IsLockedOut" class="form-check-label">@sr["Account Locked"]</label>
                </div>
            </div>
        </div>
    </div>
    @if (Model.UserId != Guid.Empty)
    {
        <div class="form-group">
            <label asp-for="UserId">@sr["UserId"]</label>
            <label class="control-label">@Model.UserId.ToString()</label>
        </div>
    }
    <div class="form-group">
        <label asp-for="Email">@sr["Email"]</label>
        <input asp-for="Email" class="form-control" />
        <span asp-validation-for="Email" class="invalid-feedback"></span>
    </div>
    <div class="form-group">
        <label asp-for="Username">@sr["Username"]</label>
        <input asp-for="Username" class="form-control"
               data-remote-validate-onblur="true"
               data-error-target-id="spnUserNameWarn"
               data-additional-input-ids="UserId"
               data-validation-url='@Url.Action("UsernameAvailable", "Account")' />
        <span asp-validation-for="Username" class="invalid-feedback"></span>
        <span id="spnUserNameWarn" class="text-danger" data-error-message='@sr["Username is already in use"]'></span>
        @Html.ValidationMessage("usernameerror", new { @class = "text-danger" })
    </div>
    <div class="form-group">
        <label asp-for="DisplayName">@sr["Display Name"]</label>
        <input asp-for="DisplayName" class="form-control" />
        <span asp-validation-for="DisplayName" class="invalid-feedback"></span>
    </div>
    <div class="form-group">
        <label asp-for="FirstName">@sr["First Name"]</label>
        <input asp-for="FirstName" class="form-control" />
    </div>
    <div class="form-group">
        <label asp-for="LastName">@sr["Last Name"]</label>
        <input asp-for="LastName" class="form-control" />
    </div>
    <div class="form-group">
        <label asp-for="DateOfBirth">@sr["Date of Birth"]</label>
        <input name="DateOfBirth" value="@(Model.DateOfBirth.HasValue ? Model.DateOfBirth.Value.ToString("d") : string.Empty)"
               class="form-control"
               data-bs-datepicker="true"
               data-bs-datepicker-debug="false"
               data-bs-datepicker-keepOpen="false"
               data-bs-datepicker-allowInputToggle="true"
               data-bs-datepicker-viewMode="years"
               data-bs-datepicker-usecurrent="false"
               data-bs-datepicker-format="L"
               data-bs-datepicker-locale="@System.Globalization.CultureInfo.CurrentCulture.Name"
               data-bs-datepicker-mindate="@DateTime.UtcNow.AddYears(-120).ToString("O")"
               data-bs-datepicker-maxdate="@DateTime.UtcNow.AddYears(-10).ToString("O")"
               data-bs-datepicker-viewDate="@DateTime.UtcNow.AddYears(-10).ToString("O")" />
        <span asp-validation-for="DateOfBirth" class="invalid-feedback"></span>
    </div>
    <div class="form-group">
        <label asp-for="TimeZoneId">@sr["Time Zone"]</label>
        <select asp-for="TimeZoneId" asp-items="Model.AllTimeZones" class="form-control"></select>
        <span asp-validation-for="TimeZoneId" class="invalid-feedback"></span>
    </div>
    <div class="form-group">
        <label asp-for="WebSiteUrl">@sr["Website Url"]</label>
        <input asp-for="WebSiteUrl" class="form-control" />
    </div>
    <partial name="UserEditMiddlePartial" model="Model" />
    <div class="form-group">
        <label asp-for="Comment"></label>
        <textarea class="form-control" rows="5" asp-for="Comment"
                  data-ckeditor-unobtrusive=""
                  data-ckeditor-config-url="@ckOptions.CustomConfigPath"
                  data-ckeditor-config-language="@ckOptions.LanguageCode"
                  data-ckeditor-config-dropfileuploadurl="@ckOptions.DropFileUrl"
                  data-ckeditor-config-filebrowserurl="@ckOptions.FileBrowseUrl"
                  data-ckeditor-config-imagebrowseurl="@ckOptions.ImageBrowseUrl"></textarea>
    </div>

    <div class="form-group">
        <button id="btnSave" type="submit" class="btn btn-primary" data-enabled-text='@sr["Save"]' data-disabled-text='@sr["Working..."]'>@sr["Save"]</button>
        @if (Model.UserId != Guid.Empty)
        {

            <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#confirmDeleteModal">
                @sr["Delete"]
            </button>
            @Html.ValidationMessage("deleteerror", new { @class = "text-danger" })
            <a asp-controller="UserAdmin" asp-action="ChangeUserPassword" asp-route-siteid="@Model.SiteId" asp-route-userid="@Model.UserId">@sr["Change Password"]</a>
        }
    </div>
    <div asp-validation-summary="All" class="text-danger"></div>
</form>
@if (Model.UserId != Guid.Empty)
{
    <form id="deleteform" class="form-inline" asp-controller="UserAdmin" asp-action="UserDelete">
        <input asp-for="SiteId" type="hidden" />
        <input asp-for="UserId" type="hidden" />
        <div class="modal fade" id="confirmDeleteModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteHeading">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="confirmDeleteHeading">@sr["Confirm Delete"]</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        @string.Format(sr["Are you sure you want to delete the user {0}? You cannot undo this action."], Model.DisplayName)
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">@sr["Cancel"]</button>
                        <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                    </div>
                </div>
            </div>
        </div>
    </form>
}
<partial name="UserRoles" model="Model" />
<partial name="UserClaims" model="Model" />

@section SideNav {
    <partial name="AdminSideNav" />
}
@section Toolbar{
    <partial name="AdminSideNavToggle" />
}
@section Scripts {
    <partial name="AdminSideNavScripts" />
    <partial name="UserEditScriptsPartial" />

}
